package com.hwadee.teachingprocessmanagementsystem.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description: 跨域处理配置类
 * @Author: Jukomu
 * @Package: com.mypetstorespring.config
 * @Project: MyPetStore-spring
 * @name: CorsConfig
 * @Date: 2024/3/10 1:58
 * @Filename: CorsConfig
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry
                // 运许访问的路径
                .addMapping("/**")
                // 允许的请求来源
                .allowedOrigins("http://localhost:5173")
                // 允许跨域访问的方法
                .allowedMethods("GET", "POST", "DELETE", "PUT", "OPTION")
                // 是否允许携带参数
                .allowCredentials(true)
                // 最大响应时间
                .maxAge(3600)
                // 允许客户端携带的请求头
                .allowedHeaders("*");
    }
}
